package com.muyu.danmo.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.danmo.service.OrderFunctionService;
import com.muyu.system.domain.dto.*;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/function")
@RequiredArgsConstructor
public class OrderFunctionController {

    private final OrderFunctionService orderFunctionService;

    /**
     * 取消订单
     * @param cancelOrderDTO
     * @return
     */
    @PostMapping("/cancel")
    public Result<String> cancelOrder(@RequestBody @Valid CancelOrderDTO cancelOrderDTO){
        orderFunctionService.cancelOrder(cancelOrderDTO);
        return Result.success("取消订单成功");
    }


    /**
     * 直接关闭订单订单
     * @param closeOrderDTO
     * @return
     */
    @PostMapping("/close/order")
    public Result<String> closeOrder(@RequestBody @Valid CloseOrderDTO closeOrderDTO){
        orderFunctionService.closeOrder(closeOrderDTO);
        return Result.success("取消订单成功");
    }




    /**
     * 修改订单地址
     * @param updateAddressDTO
     * @return
     */
    @PostMapping("/address")
    public Result<String> updateAddress(@RequestBody @Valid UpdateAddressDTO updateAddressDTO){
        orderFunctionService.updateAddress(updateAddressDTO);
        return Result.success("修改地址成功");
    }

    /**
     * 订单取消并退款
     * @param cancelRefundDTO
     * @return
     */
    @PostMapping("/cancel/refund")
    public Result<String> cancelRefund(@RequestBody @Valid CancelRefundDTO cancelRefundDTO){
        orderFunctionService.cancelRefund(cancelRefundDTO);
        return Result.success("取消退款成功");
    }

    /**
     * 确认发货
     * @param confirmShipmentDTO
     * @return
     */
    @PostMapping("/confirm/shipment")
    public Result<String> confirmShipment(@RequestBody @Valid ConfirmShipmentDTO confirmShipmentDTO){
        orderFunctionService.confirmShipment(confirmShipmentDTO);
        return Result.success("成功！");
    }

    /**
     * 快递查询
     * @param expressDTO
     * @return
     */
    @PostMapping("/express")
    public Result<Object> express(@RequestBody @Valid ExpressDTO expressDTO){
        return Result.success(orderFunctionService.express(expressDTO));
    }


    /**
     * 确认收货
     * @param receivingDTO
     * @return
     */
    @PostMapping("/receiving")
    public Result<String> receiving(@RequestBody @Valid ReceivingDTO receivingDTO){
        orderFunctionService.receiving(receivingDTO);
        return Result.success("成功！");
    }


    /**
     * 评价
     * @param list
     * @return
     */
    @PostMapping("/evaluation")
    public Result<String> evaluation(@RequestBody @Valid List<EvaluationDTO> list){
        list.forEach(orderFunctionService::evaluation);
        return Result.success("成功！");
    }

    /**
     * 删除订单
     * @param deleteOrderDTO
     * @return
     */
    @DeleteMapping("/delete/order")
    public Result<String> deleteOrder(@RequestBody @Valid DeleteOrderDTO deleteOrderDTO){
        orderFunctionService.deleteOrder(deleteOrderDTO);
        return Result.success("成功！");
    }





}
